<template lang="html">
  <div class="review">

    <!-- <div class='clearfix'>
      <el-button type="danger" class='pull-right mb10' icon="el-icon-delete" style='margin-right:10px;' @click="tourl('/content/trash')">回收箱</el-button>
    </div> -->

    <div class='searchView'>
      <el-form :inline="true" class="demo-form-inline">
        
        <el-form-item label="">
          <el-input @keydown.enter='getList(1)' v-model='searchForm.name' placeholder='输入用户名称…'></el-input>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" @click='getList(1)'>查询</el-button>
        </el-form-item>

      </el-form>
    </div>

    <div class='tableView'>
      <el-tag type="info" class='mb10'>共{{totalData}}条记录</el-tag>
      <el-table
        ref="multipleTable"
        :data="tableData"
        v-loading='loading'
        align='center'
        border
        height='500'
        tooltip-effect="dark">

        <el-table-column
        align='center'
        prop='fullName'
        label="用户名">
        </el-table-column>

        <el-table-column
        align='center'
        prop='email'
        label="邮箱">
        </el-table-column>

        <el-table-column
        align='center'
        prop='mobile'
        label="手机号">
        </el-table-column>


        <el-table-column
        align='center'
        prop='createTime'
        label="提交时间">
        </el-table-column>

        <el-table-column
        align='center'
        label="审核状态">
          <template slot-scope="scope">
            <el-tag v-show='scope.row.status == 0'>待审核</el-tag>
            <el-tag v-show='scope.row.status == 1' type="success">已通过</el-tag>
            <el-tag v-show='scope.row.status == 2' type="danger">未通过</el-tag>
          </template>
        </el-table-column>

        <el-table-column
        label=""
        width='220'
        align='center'>
          <template slot-scope="scope">
            <el-button size='mini' type="primary" v-show='scope.row.status == 0' @click='review(scope.row)'>审核</el-button>
            <el-button size='mini' type="primary" v-show='scope.row.status != 0' @click='review(scope.row)'>审核详情</el-button>
          </template>
        </el-table-column>

      </el-table>

      <div class="pageBlock">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page.sync="currentPage"
          :page-size="pageSize"
          layout="prev, pager, next, jumper, sizes"
          :total="totalData">
        </el-pagination>
      </div>
    </div>

    <el-dialog
      title="审核"
      :visible.sync="dialogVisible"
      width="500px">

      <el-form ref="form" label-width="100px">

        <el-form-item label="用户名">
          {{form.fullName}}
        </el-form-item>
        <el-form-item label="手机号">
          {{form.mobile}}
        </el-form-item>
        <el-form-item label="邮箱">
          {{form.email}}
        </el-form-item>
        <el-form-item label="个人介绍">
          {{form.personalIntroduction}}
        </el-form-item>
        <el-form-item label="已发布文章">
          {{form.alreadyPublishArticle}}
        </el-form-item>
        <el-form-item label="已出版书籍">
          {{form.alreadyPublishBookInfo}}
        </el-form-item>
        <el-form-item label="身份证正面">
          <img :src="form.idCardFront" style='width:300px;height:200px;'>
        </el-form-item>
        <el-form-item label="身份证反面">
          <img :src="form.idCardBack" style='width:300px;height:200px;'>
        </el-form-item>
        <el-form-item label="审核状态">
          <el-tag v-show='form.status == 0'>待审核</el-tag>
          <el-tag v-show='form.status == 1' type="success">已通过</el-tag>
          <el-tag v-show='form.status == 2' type="danger">未通过</el-tag>
        </el-form-item>
        <el-form-item label="提交时间">
          {{form.createTime}}
        </el-form-item>
        
            
      </el-form>

      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button v-show='form.status == 0' type="primary" @click="submitAdd(form.id,1)">通 过</el-button>
        <el-button v-show='form.status == 0' type="danger" @click="submitAdd(form.id,2)">不通过</el-button>
      </span>
    </el-dialog>

  </div>
</template>
<script>
export default {

  data () {
    return {
      tableData:[],
      loading:false,
      status:'UN_PUBLISHED',
      date:'',
      options: [
        {
          value: '',
          label: '全部'
        },
        {
          value:'UN_PUBLISHED',
          label:'全站用户'
        },
        {
          value:'PUBLISHED',
          label:'书籍作者'
        },
        {
          value:'AUDITING',
          label:'普通用户'
        }
      ],
      totalData:0,
      pageSize:10,
      searchUserId:null,
      currentPage:1,
      dialogVisible:false,
      form:{},
      searchForm:{
        name:''
      }
    }
  },
  methods:{
    submitAdd(id,status){
      tools.ajax({
          url:'/v1/book/publish/updateAuthorPublish',
          data:{
            id,
            status
          },
          type:'POST'
      })
      .then(res => {
        this.loading = false;
        if(res.code == 200){
          tools.toastOk('审核成功');
          this.dialogVisible = false;
          this.getList(1);
        }
      })
      .catch(e => {
        this.loading = false;
      })
    },
    review(row){
      this.form = {};
      this.form = row;
      this.dialogVisible = true;
    },
    delIt(userId,id){
      this.$confirm('是否确认删除？',{center:true})
      .then(res =>{
        tools.toastOk('删除成功');
        return
        this.loading = true;
        tools.ajax({
            url:`/dynamic_service/v1/users/${userId}/dynamic/squares/${id}`,
            data:{
              del:true
            },
            type:'PUT'
        })
        .then(res => {
          this.loading = false;
          if(res.code == 200){
            tools.toastOk('删除成功');
            this.getList(1);
          }
        })
        .catch(e => {
          this.loading = false;
        })

      }).catch( e=> {})
    },
    create(){
      if(!this.searchUserId){
        tools.toastWarn('请选择用户');
        return
      };

      this.tourl('/content/user/create',{userId:this.searchUserId});
    },
    tourl(url,query){
      tools.router.push({path:url,query:query || {}})
    },
    getList(page){
      if(page){
        this.currentPage = page;
      }

      let data = {
        page:this.currentPage,
        pageSize:this.pageSize
      };

      for(let i in this.searchForm){
        data[i] = this.searchForm[i]
      }

      this.loading = true;
      tools.ajax({
        url:'/v1/book/publish/list',
        data,
        type:'GET'
      })
      .then(res => {
        this.loading = false;
        if(res.code == 200){
          this.tableData = res.data.rows;
          this.totalData = +res.data.total;
        }
      })
      .catch(e => {
        this.loading = false;
      })
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.currentPage = val;
      this.getList();
    }
  },
  mounted(){
    var _this = this;
    this.getList();
  },
  components:{
  }
}
</script>

<style scoped lang='scss'>
  @import '../../assets/scss/tool.scss';
  .review{
    
  }
  .cover{
    width: 100px;
    height: 100px;
  }
</style>